package link.hwx.controller.oa;

import com.alibaba.fastjson.JSONObject;
import link.hwx.util.HttpManager;
import link.hwx.util.IdentityVerifyUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * 流程退回实例
 * description :
 * author ：JHY
 * date : 2020/6/4
 * version : 1.0
 */
public class RequestRejectDemo {

    public static void main(String[] args) {
        rejectRequest("66067", "22");
    }

    /**
     * 流程退回
     */
    public static void rejectRequest(String requestid, String userid) {
        IdentityVerifyUtil identityVerifyUtil = IdentityVerifyUtil.getInstance();
        String spk = identityVerifyUtil.getSPK();
        String secret = identityVerifyUtil.getSECRET();
        String token = identityVerifyUtil.getToken();
        if (spk == null || secret == null || token == null) {
            return;
        }
        Map<String, String> heads = IdentityVerifyUtil.getHttpHeads(token, userid, spk);
        String url = IdentityVerifyUtil.HOST + "/api/workflow/paService/rejectRequest";
        HttpManager http = new HttpManager();

        Map<String, String> params = new HashMap<>();
        params.put("requestId", requestid);
        params.put("remark", "restful接口退回流程测试");

        //默认是按出口退回
        //自由退回参数设置
//        Map<String, String> otherParams = new HashMap<>();
//        otherParams.put("RejectToType", "0");
//        otherParams.put("RejectToNodeid", "339");
//        params.put("otherParams", JSONObject.toJSONString(otherParams));

        try {
            http.cookieStore.clear();
            String res = http.postDataSSL(url, params, heads);
            System.out.println(res);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
